package cn.gqr.service.impl;

import cn.gqr.entity.Type;
import cn.gqr.mapper.TypeMapper;
import cn.gqr.service.TypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    //类型添加
    @Override
    public boolean insertType(Type type) {
        return typeMapper.insert(type)>0;
    }

    //类型修改
    @Override
    public boolean updateType(Type type) {
        return typeMapper.updateById(type)>0;
    }

    //类型删除
    @Override
    public boolean deleteType(Integer id) {
        UpdateWrapper<Type> uw = new UpdateWrapper<>();
        uw.lambda().eq(Type::getId,id).set(Type::getIsdel,1);
        boolean update = update(uw);
        return update;
    }

    //类型查询
    @Override
    public List<Type> selectTypes() {
        QueryWrapper<Type> qw = new QueryWrapper<>();
        qw.lambda().eq(Type::getIsdel,0);
        List<Type> types = typeMapper.selectList(qw);
        return types;
    }
}
